package fy.hr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.seeyon.ctp.organization.bo.V3xOrgMember;

import fy.config.FyConfig;
import fy.form.listen.dao.MyOrgManager;
import fy.util.DBUtil;
import fy.util.MyUtil;

public class LeaveForm_FindUserInfoDao {

	private String userName;

	private String code;

	private String post;

	private String dep;

	private String reportDate;

	private long memberID;

	private String remainDays;

	public String getRemainDays() {
		return remainDays;
	}

	public boolean query() {
		boolean success = false;
		V3xOrgMember member = MyOrgManager.getInstance()
				.getMemberByID(memberID);
		code = member.getCode();

		if (code != null && !"".equals(code)) {
			Connection conn = null;
			PreparedStatement st = null;
			ResultSet rs = null;
			try {
				conn = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());
                
				st = conn
						.prepareStatement("select tab1.psncode,tab1.psnname,tab2.deptname,tab3.jobname,tab4.basgroupdef4 from bd_psndoc tab1 join bd_deptdoc tab2 on tab1.pk_deptdoc=tab2.pk_deptdoc join om_job tab3 on tab1.pk_om_job=tab3.pk_om_job join bd_psnbasdoc tab4 on tab1.pk_psnbasdoc=tab4.pk_psnbasdoc where tab1.psnclscope in ('0','5') and tab1.psncode=?");

				st.setString(1, code);

				rs = st.executeQuery();
				if (rs.next()) {
					userName = rs.getString(2);
					dep = rs.getString(3);
					post = rs.getString(4);
					reportDate = rs.getString(5);

					DBUtil.close(rs, st);

					st = conn
							.prepareStatement("select to_char(t1.restdayorhour,'90.9') from TBM_LMHOLIDAY t1, bd_psndoc t2,tbm_timeitem t3 where t2.psnclscope in ('0', '5') and t2.psncode=? and t1.pk_corp=t2.pk_corp and t1.pk_psndoc = t2.pk_psndoc and t3.timeitemname='年假' and t3.pk_timeitem=t1.pk_timeitem and  t1.curyear=?");
					st.setString(1, code);
					st.setString(2, MyUtil.getYear());

					rs = st.executeQuery();
					if (rs.next()) {
						remainDays = rs.getString(1);
					}
					success = true;
				}

			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				DBUtil.close(rs, st, conn);
			}
		}

		return success;
	}

	public void setMemberID(long memberID) {
		this.memberID = memberID;
	}

	public String getUserName() {
		return userName;
	}

	public String getCode() {
		return code;
	}

	public String getPost() {
		return post;
	}

	public String getDep() {
		return dep;
	}

	public String getReportDate() {
		return reportDate;
	}
}
